<?php

	require('../includes/functions.php');
	
	$id = isset($_POST['id']) ? $_POST['id'] : null;
	$name = isset($_POST['name']) ? trim($_POST['name']) : null;
	$address = isset($_POST['address']) ? trim($_POST['address']) : null;
	$contact = isset($_POST['contact']) ? trim($_POST['contact']) : null;
	$email = isset($_POST['email']) ? trim($_POST['email']) : null;
	$gender = isset($_POST['gender']) ? trim($_POST['gender']) : null;
	$month = $_POST['month'] < 10 ? "0".$_POST['month']:$_POST['month'];
	$day = $_POST['day'] < 10 ? "0".$_POST['day']:$_POST['day'];
	$year = $_POST['year'];
	$birthdate = $year . '-' . $month . '-' . $day;
	$department = $_POST['department'];
	$job = $_POST['job'];
	$status = $_POST['status'];
	
	if ($name == "") {
		$_SESSION['error'] = "Name should not be empty!";
	}
	else if ($address == "") {
		$_SESSION['error'] = "Address should not be empty!";
	}
	else if ($contact == "") {
		$_SESSION['error'] = "Contact should not be empty!";
	}
	else if ($email == "") {
		$_SESSION['error'] = "Email should not be empty!";
	}
	else {
		addEmployee($name, $address, $contact, $email, $gender, $birthdate, $department, $job, $status);
		$_SESSION['message'] = "Employee added!";
	}
	
	$location = "../add_employee.php";
	
	header("Location: $location");

?>